import time

import cv2
import numpy as np
#B is ruler
imgB=cv2.imread("./AB_photo/B1.png")
imgA=cv2.imread("./AB_photo/A2.jpg")


'''
hsvimgB=cv2.cvtColor(imgB,cv2.COLOR_BGR2HSV)#转HSV色彩空间
hsvimgB=cv2.GaussianBlur(hsvimgB,(5,5),0)
edged=cv2.Canny(hsvimgB,70,200)
edged=cv2.dilate(edged,None,iterations=1)
edged=cv2.erode(edged,None,iterations=1)
colorLow=np.array([156,43,46])#红色颜色阈值
colorHigh=np.array([180,255,255])
mask=cv2.inRange(hsvimgB,colorLow,colorHigh)
'''
height1, width1 = imgA.shape[:2]
imgA=cv2.resize(imgA,(int(width1/10),int(height1/10)),interpolation=cv2.INTER_CUBIC)#缩放后的原图
#imgA=cv2.bilateralFilter(imgA,0,50,6)
# cv2.imshow('imgA1',imgA)

time1=time.time()
imgA=cv2.cvtColor(imgA,cv2.COLOR_BGR2BGRA)
imgA=cv2.GaussianBlur(imgA,(3,3),0)
# imgA=cv2.Canny(imgA,70,200)
imgA=cv2.medianBlur(imgA,3)
#imgA=cv2.bilateralFilter(imgA,0,50,6)
imgA=cv2.dilate(imgA,None,iterations=1)
imgA=cv2.erode(imgA,None,iterations=1)
time2=time.time()
print(time2-time1)


# cv2.imshow('img',imgB)
# cv2.imshow('imghsv',mask)
# cv2.imshow('edged',edged)
cv2.imshow('imgA',imgA)
cv2.waitKey(0)
cv2.destroyAllWindows()